//
//  MyAdoptedViewController.m
//  PigMarket
//
//  Created by mac on 2019/5/6.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "MyAdoptedViewController.h"
#import "AdoptedPigsViewController.h"
#import "FreeAdoptedPigsViewController.h"
#import "OrderAdoptedPigsViewController.h"
#import "TransferManagerViewController.h"

@interface MyAdoptedViewController ()<XXPageTabViewDelegate>

@property (nonatomic , strong) UIImageView *bgImg;
@property (nonatomic , strong) XXPageTabView *pageTabView;
@property (nonatomic , strong) AdoptedPigsViewController *adoptedVC;
@property (nonatomic , strong) FreeAdoptedPigsViewController *freeVC;
@property (nonatomic , strong) OrderAdoptedPigsViewController *orderVC;
@property (nonatomic , strong) UIButton *toAdoptBtn;

@end

@implementation MyAdoptedViewController


#pragma mark - view life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpView];
    [self setUpNav];
}


- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

#pragma mark - init method

- (void)setUpView {
    [self initView];
    [self initLayout];
}


- (void)setUpNav{
    
    {
        self.baseNavView.navTitleLabel.text = @"我的领养";
        self.baseNavView.navTitleLabel.textColor = KWhiteColor;
        self.baseNavView.backgroundColor = KClearColor;
        self.baseNavView.line.hidden = YES;
        
        [self.baseNavView.leftNavBtn setImage:[UIImage imageNamed:@"nav_white"] forState:UIControlStateNormal];
        
        self.baseNavView.rightNavBtn.hidden = NO;
        self.baseNavView.rightNavBtn.width = 60;
        self.baseNavView.rightNavBtn.mj_x = KScreenWidth - 75;
        [self.baseNavView.rightNavBtn setTitle:@"转让管理" forState:UIControlStateNormal];
        [self.baseNavView.rightNavBtn setTitleColor:KWhiteColor forState:UIControlStateNormal];
        
        @weakify(self);
        self.baseNavView.rightBlock = ^{
            @strongify(self);
            TransferManagerViewController *vc = [[TransferManagerViewController alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        };
        
        [self.bgImg addSubview:self.baseNavView];
    }
}


- (void)initView {
    
    [self addChildViewController:self.adoptedVC];
    [self addChildViewController:self.freeVC];
    [self addChildViewController:self.orderVC];
    
    [self.view addSubview:self.bgImg];
    [self.view addSubview:self.pageTabView];

    [[UIApplication sharedApplication].keyWindow addSubview:self.toAdoptBtn];
}


- (void) initLayout {
    
    [self.bgImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(177 + TJ_StatusBarHeight);
    }];
    
    [self.pageTabView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(TJ_NavBarHeight);
    }];
}


#pragma mark - delegate

- (void)scrollToLast:(id)sender {
    [self.pageTabView setSelectedTabIndexWithAnimation:self.pageTabView.selectedTabIndex-1];
}

- (void)scrollToNext:(id)sender {
    [self.pageTabView setSelectedTabIndexWithAnimation:self.pageTabView.selectedTabIndex+1];
}

- (void)pageTabViewDidEndChange{
}

#pragma mark - getter and setter

- (UIImageView *)bgImg {
    if (!_bgImg) {
        _bgImg = [[UIImageView alloc] init];
        _bgImg.image = [UIImage imageNamed:@"meat_adopt_bg"];
        _bgImg.userInteractionEnabled = YES;
    }
    return _bgImg;
}


- (XXPageTabView *)pageTabView {
    if (!_pageTabView) {
        
        _pageTabView = [[XXPageTabView alloc] initWithChildControllers:self.childViewControllers childTitles:@[@"饲养仔猪",@"免费试养",@"99元预定"]];
        _pageTabView.delegate = self;
        _pageTabView.indicatorStyle = XXPageTabIndicatorStyleFollowText;//跟随文本变化长度
        _pageTabView.titleStyle = XXPageTabTitleStyleGradient;//渐变
        _pageTabView.selectedTabIndex = 0;
        _pageTabView.separatorColor = [UIColor clearColor];
        _pageTabView.tabItemFont = [UIFont systemFontOfSize:14];
        _pageTabView.indicatorHeight = 0;
        _pageTabView.unSelectedColor = [UIColor colorWithHexString:@"#FFFFFF"];
        _pageTabView.selectedColor = [UIColor colorWithHexString:@"#FFFFFF"];
        _pageTabView.tabBackgroundColor = [UIColor clearColor];
        _pageTabView.bodyBackgroundColor = [UIColor clearColor];
    }
    return _pageTabView;
}


- (AdoptedPigsViewController *)adoptedVC {
    if (!_adoptedVC) {
        _adoptedVC = [[AdoptedPigsViewController alloc] init];
    }
    return _adoptedVC;
}


- (FreeAdoptedPigsViewController *)freeVC {
    if (!_freeVC) {
        _freeVC = [[FreeAdoptedPigsViewController alloc] init];
    }
    return _freeVC;
}


- (OrderAdoptedPigsViewController *)orderVC {
    if (!_orderVC) {
        _orderVC = [[OrderAdoptedPigsViewController alloc] init];
    }
    return _orderVC;
}


@end
